(function ($) {

    var initRight = '-582px';
    var endRight = 0;
    // 学历查看详情按钮点击事件
    $("#degree_detail").on('click', function (e) {
        e.preventDefault();
        e.stopPropagation();
        var _this = $(this);
        var data = JSON.parse(_this.attr('data-item') || '{}');
        degreeeDetailTpl(data);

        $(".detail-section-wrap").stop().animate({
            right: endRight
        }, 200)
    });

    $('.detail-section-wrap').on('click', function (e) {
        $(".detail-section-wrap").stop().animate({
            right: initRight
        }, 200)
    });
    $('.container').click(
        function(){
            $('.detail-section-wrap').trigger('click');
        })

    $("#company_detail").click(function (e) {
        e.preventDefault();
        e.stopPropagation();
        var _this = $(this);
        var data = JSON.parse(_this.attr('data-item') || '{}');
        companyDetailTpl(data);

        $(".detail-section-wrap").stop().animate({
            right: endRight
        }, 200)

    });


    $("#investment_detail").click(function (e) {
        e.preventDefault();
        e.stopPropagation();
        var _this = $(this);
        var data = JSON.parse(_this.attr('data-item') || '{}');
        investmentDetailTpl(data);

        $(".detail-section-wrap").stop().animate({
            right: endRight
        }, 200)

    });

    $("#degreedetailLink").click(function () {
        var _this = $(this);
        var data = JSON.parse(_this.attr('data-item') || '{}');
        degreeeDetailTpl(data);

        $(".detail-section-wrap").stop().animate({
            right: endRight
        }, 200)

    });


    $("#air_detail").click(function (e) {
        e.preventDefault();
        e.stopPropagation();
        var _this = $(this);
        var data = JSON.parse(_this.attr('data-item') || '{}');
        airDeatailTpl(data);

        $(".detail-section-wrap").stop().animate({
            right: endRight
        }, 200)

    });

})(jQuery);


// 渲染工商详情框函数
function companyDetailTpl(itemData) {
    var tplStr = "";
    tplStr += "<div class='detail-section'>";
    tplStr += "<div class='consequence-table-wrap' />";
    tplStr += "<div class='consequence-section'>";
    tplStr += "<div class='consequence-title'>企业信息</div>";
    tplStr += "<div class='consequence-table-wrap'>";

    tplStr = companyCommonTpl(tplStr, itemData);

    tplStr += "</div></div></div>";
    tplStr += "<div class='slide-right'></div>";


    console.log(tplStr);
    $('.detail-section-wrap').html(tplStr);

    var frg = document.createDocumentFragment();
    var list = $.makeArray($(".company-info")).sort(function (a, b) {
        var curIn = parseFloat(a.getAttribute("data-order"));
        var curNext = parseFloat(b.getAttribute("data-order"));
        return curIn - curNext;
    });
    $.each(list, function (index, domEle) {
        frg.appendChild(domEle);
    });
    $('.consequence-table-wrap').eq(1).append(frg);
    frg = null;
}


// 渲染详情框函数
function investmentDetailTpl(itemData) {

    var tplStr = "";
    tplStr += "<div class='detail-section'>";
    tplStr += "<div class='consequence-table-wrap' />";

    tplStr += "<div class='consequence-section'>";
    tplStr += "<div class='consequence-title'>个人工商信息</div>";
    tplStr += "<div class='consequence-table-wrap'>";

    tplStr = investmentInfoTpl(tplStr, itemData);

    tplStr += "</div></div></div>";
    tplStr += "<div class='slide-right'></div>";

    $('.detail-section-wrap').html(tplStr);

    var frg = document.createDocumentFragment();
    var list = $.makeArray($(".investment-info")).sort(function (a, b) {
        var curIn = parseFloat(a.getAttribute("data-order"));
        var curNext = parseFloat(b.getAttribute("data-order"));
        return curIn - curNext;
    });
    $.each(list, function (index, domEle) {
        frg.appendChild(domEle);
    });
    $('.consequence-table-wrap').eq(1).append(frg);
    frg = null;
}


function degreeeDetailTpl(data){

    var tplStr = "";
    tplStr += "<div class='detail-section'>";
    tplStr += "<div class='consequence-table-wrap' />";
    tplStr += "<div class='consequence-section'>";
    tplStr += "<div class='consequence-title'>学历信息</div>";
    tplStr += "<div class='consequence-table-wrap'><table class='consequence-table'>";
    tplStr += "<tbody><tr> <td>姓名</td><td>";
    tplStr += data.user_name+"</td></tr><tr><td>身份证</td><td>";
    tplStr += data.identity+"</td></tr><tr></tbody></table></div>";
    tplStr += "<div class='consequence-table-wrap'><table class='consequence-table'>";
    tplStr += "<tbody><tr><td>毕业院校</td><td>"+data.graduate+"</td></tr>";
    tplStr += "<tr><td>学历</td><td>"+data.education_degree+"</td></tr>";
    tplStr += "<tr><td>入学年份</td><td>"+data.enrol_date+"</td></tr>";
    tplStr += "<tr><td>专业</td><td>"+data.speciality_name+"</td></tr>";
    tplStr += "<tr><td>毕业时间</td><td>"+data.graduate_time+"</td></tr>";
    tplStr += "<tr><td>毕业结论</td><td>"+data.study_result+"</td></tr>";
    tplStr += "<tr><td>学历类型</td><td>"+data.study_style+"</td></tr>";
    tplStr += "</tbody></table></div>";
    tplStr += "<div class='consequence-table-wrap' style='padding-top:20px;padding-bottom:30px'>";
    tplStr += "<table class='consequence-table'><tr><td><span class='vertical-top'>照片</span></td> <td>";
    tplStr += "<span class='consequence-avatar-wrap'>正在加载中...<img class='consequence-avatar' src='data:image/jpeg;base64,"+data.photo+"' alt='学历照片'></span>";
    tplStr += "</td></tr></table></div></div></div>";
    tplStr += "<div class='slide-right' id='slide-right'></div>";

    $('.detail-section-wrap').html(tplStr);
}



function airDeatailTpl(data) {

    var tplStr = "";
    tplStr += "<div class='detail-section'>";
    tplStr += "<div class='consequence-table-wrap' />";
    tplStr += "<div class='consequence-section'>";
    tplStr += "<div class='consequence-title'>乘机人价值分析查询结果</div><div class='consequence-table-wrap'>";
    tplStr += "<table class='consequence-table'><tbody>";
    tplStr += "<tr><td>身份证号</td><td>"+data.id_number+"</td></tr>";
    tplStr += "<tr><td>姓名</td><td>"+data.name+"</td></tr>";
    tplStr += "<tr><td>1 年中飞行次数</td><td>"+data.year_fly_count+"</td></tr>";
    tplStr += "<tr><td>最繁忙的月份乘机次数</td><td>"+data.month_fly_count+"</td></tr>";
    tplStr += "<tr><td>最繁忙的乘机月份</td><td>"+data.month_fly_date+"</td></tr>";
    tplStr += "<tr><td>1 年内平均折扣</td><td>"+data.average_discount+"</td></tr>";
    tplStr += "<tr><td>商务舱乘机次数</td><td>"+data.f_cabin_count+"</td></tr>";
    tplStr += "<tr><td>公务舱乘机次数</td><td>"+data.c_cabin_count+"</td></tr>";
    tplStr += "<tr><td>经济舱乘机次数</td><td>"+data.y_cabin_count+"</td></tr>";
    tplStr += "<tr><td>最频繁乘机出发城市0</td><td>"+data.frequently_from_city_0+"</td></tr>";
    tplStr += "<tr><td>最频繁乘机出发城市次数0</td><td>"+data.frequently_from_city_count_0+"</td> </tr>";
    tplStr += "<tr><td>最频繁乘机出发城市1</td><td>"+data.frequently_from_city_1+"</td></tr>";
    tplStr += "<tr><td>最频繁乘机出发城市次数1</td><td>"+data.frequently_from_city_count_1+"</td></tr>";
    tplStr += "<tr><td>最频繁乘机出发城市2</td><td>"+data.frequently_from_city_2+"</td></tr>";
    tplStr += "<tr><td>最频繁乘机出发城市次数2</td><td>"+data.frequently_from_city_count_2+"</td></tr>";
    tplStr += "<tr><td>最频繁乘机到达城市0</td><td>"+data.frequently_destination_city_0+"</td></tr>";
    tplStr += "<tr><td>最频繁乘机到达城市次数0</td><td>"+data.frequently_destination_city_count_0+"</td></tr>";
    tplStr += "<tr><td>最频繁乘机到达城市1</td><td>"+data.frequently_destination_city_1+"</td></tr>";
    tplStr += "<tr><td>最频繁乘机到达城市次数1</td><td>"+data.frequently_destination_city_count_1+"</td></tr>";
    tplStr += "<tr><td>最频繁乘机到达城市2</td><td>"+data.frequently_destination_city_2+"</td></tr>";
    tplStr += "<tr><td>最频繁乘机到达城市次数2</td><td>"+data.frequently_destination_city_count_2+"</td></tr>";
    tplStr += "<tr><td>最频繁使用航空公司</td><td>"+data.frequently_airline_name+"</td></tr>";
    tplStr += "<tr><td>最频繁使用航空公司乘机次数</td><td>"+data.frequently_airline_count+"</td></tr>";
    tplStr += "<tr><td>国内飞行次数</td><td>"+data.internal_count+"</td></tr>";
    tplStr += "<tr><td>国外飞行次数</td><td>"+data.foreign_count+"</td></tr>";
    tplStr += "<tr><td>免票次数</td><td>"+data.free_count+"</td></tr>";
    tplStr += "<tr><td>平均票价</td><td>"+data.average_price+" 元</td></tr>";
    tplStr += "<tr><td>总延误时间</td><td>"+data.total_delay_time+" 分钟</td></tr>";
    tplStr += "<tr><td>平均延误时间</td><td>"+data.average_delay_time+" 分钟</td></tr>";
    tplStr += "<tr><td>平均提前多少天出票</td><td>"+data.average_ticket_day+"</td></tr>";
    tplStr += "<tr><td>最后飞行时间</td><td>"+data.last_fly_date+"</td></tr>";
    tplStr += "<tr><td>最后起飞城市</td><td>"+data.last_from_city+"</td></tr>";
    tplStr += "<tr><td>最后抵达城市</td><td>"+data.last_destination_city+"</td></tr>";
    tplStr += "<tr><td>总共飞行里程数</td><td>"+data.fly_total_milage+" KM</td></tr>";
    tplStr += "</tbody></table></div></div></div>";
    tplStr += "<div class='slide-right'></div>";
    $('.detail-section-wrap').html(tplStr);
}